#include "ArrayList.h"

#define PI 3.1415926535897931160f

void staticMatrixInit();

class Matrix {
  public:
  Matrix(int n);
  ~Matrix();
  int lines;//n*4
  float* m;
  void init(int n);
  void multi(Matrix* b, Matrix* result);
  void init();
  void zero();
  void rotateX(float a);
  void rotateY(float a);
  void rotateZ(float a);
  void move(float x, float y, float z);
  void scale(float x, float y, float z);
};

class ObjData {
  public:
  ObjData(void* res, void* texture);
  ~ObjData();
  int show;
  int vertexesCount;
  Matrix* matrix;
  Matrix* vertexes;
  Matrix* result;
  int textureMapCount;
  float* textureMap;//2*n
  int faceCount;
  int* faceVerticles;//3*n
  int* faceTexture;//3*n
  short* texture0;//256*256
  short* texture1;//128*128
  short* texture2;//64*64
  short* texture3;//32*32
};

class Projection {
  public:
  Projection(float w, float h);
  ~Projection();
  Matrix* m;
  float half_w;
  float half_h;
  float w;
  float h;
};

class Camera {
  public:
  Camera();
  ~Camera();
  float x;
  float y;
  float z;
  float direction;
  float angle;
  float moving_speed;
  float rotation_speed;
  float* floatConvertCache;
  Matrix m;
  Matrix a;
  Matrix ret;
  Matrix* cameraMatrix();
};

typedef struct {
  public:
  short* texture0;
  short* texture1;
  short* texture2;
  short* texture3;
  float v0x;
  float v0y;
  float v1x;
  float v1y;
  float v2x;
  float v2y;
  float u0x;
  float u0y;
  float u1x;
  float u1y;
  float u2x;
  float u2y;
  float vcz;
  float z;
} Face;

//void render3D(Projection* projection, Camera* cam, int objCount, ObjData** objs, Face* faces, Face** faceIndex, void* frameBuffer);
void render3D(Projection* projection, Camera* cam, ObjData** objs, int objCount, Face* faces, Face** faceIndex, void* frameBuffer, Matrix* camp, Matrix* tcamp);
